<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="utf-8">
	<title>oop9(原型-模拟extjs底层继承方式)</title>
</head>
<body>
<script type="text/javascript">

	function extend (sub, sup) {
		//目的：实现只继承父类的原型对象
		var f = new Function();	//创建中转函数
		f.prototype = sup.prototype;	//实现中转函数的原型对象和父类原型对象的转换
		sub.prototype = new f();	//原型继承
		//还原子类的构造器
		Object.defineProperty(sub.prototype, 'constructor', {
			enumerable: false, //设置能否被枚举
			value: sub
		})
		//自定义属性记录父类原型对象
		sub.superClass = sup.prototype;
		//判断父类原型的构造器
		if(sup.prototype.constructor == Object.prototype.constructor){
			Object.defineProperty(sup.prototype, 'constructor', {
				enumerable: false, //设置能否被枚举
				value: sup
			})
		}
	}
	
	function Person (name, age) {
		this.name = name;
		this.age = age;
	}

	//父类原型
	Person.prototype = {
		constructor: Person,
		getName: function () {
			alert('Hello World!');
		}
	}
	
	function Boy (name, age, sex) {
		//Person.call(this, name, age);
		Boy.superClass.constructor.call(this, name, age);
		this.sex = sex;
	}

	extend(Boy, Person);

	var b = new Boy('z3', 20, '男');

	alert(b.name);

	//alert(Boy.superClass.constructor);

</script>
</body>
</html>